//
//  RecordManager.m
//  phonebook
//
//  Created by dyang26 on 10/10/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "RecordManager.h"


@implementation RecordManager

+ (RecordManager *)sharedManager {
    static RecordManager *manager = nil;
    
    if (!manager) {
        manager = [[RecordManager alloc] init];
        [manager loadRecords];
    }
    
    return manager;
}

- (NSArray *)names {
    return records;
}

- (void)loadRecords {
    records = [[NSMutableArray arrayWithContentsOfFile:[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/names.plist"]] retain];
    
    if (!records) {
        records = [[NSMutableArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"names" ofType:@"plist"]] retain];
    }
}

- (void)saveRecords {
    // SAVE
    
    [records writeToFile:[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/names.plist"] atomically:YES];
}

@end
